package com.ebt.m.customer.entity;

import android.text.TextUtils;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import static com.ebt.m.customer.constant.Dictionary.PAY_PERIOD_MAP;
import static com.ebt.m.customer.constant.Dictionary.POLICY_STATUS_MAP;

/**
 * 保单
 * Created by archer.qi on 2016/12/12.
 */
public class PolicyBean implements Serializable {

    /* 保单ID*/
    private String policyId;

    /* 客户ID*/
    private String customerId;

    /* 公司*/
    private CompanyBean company;

    /* 主险*/
    private RiskBean risk;

    /* 保单编号*/
    private String policyNo;

    /* 投保单号*/
    private String insureNo;

    /* 保额*/
    private double coverage;

    /* 保费*/
    private double permium;

    /* 缴费方式*/
    private String payMode;

    /* 生效时间*/
    private String effectDate;

    /* 接收时间*/
    private String acceptDate;

    /* 回执时间*/
    private String receiptDate;

    /* 最近更新时间*/
    private String updateDate;

    /* 附件列表*/
    private List<Attachment> attachments;

    /* Erp保单ID*/
    private String policyErpId;

    /* Erp保单标识 <0,1> - <普通,Erp> */
    private int policyErpFlag;

    /* 保单状态号: 1-n*/
    private int policyStatusCode;

    /* 保单状态：承保件 */
    private String policyStatusValue;

    public String getPolicyId() {
        return policyId;
    }

    public void setPolicyId(String policyId) {
        this.policyId = policyId;
    }

    public String getCustomerId() {
        return customerId;
    }

    public void setCustomerId(String customerId) {
        this.customerId = customerId;
    }

    public CompanyBean getCompany() {
        return company;
    }

    public void setCompany(CompanyBean company) {
        this.company = company;
    }

    public RiskBean getRisk() {
        return risk;
    }

    public void setRisk(RiskBean risk) {
        this.risk = risk;
    }

    public String getPolicyNo() {
        return policyNo;
    }

    public void setPolicyNo(String policyNo) {
        this.policyNo = policyNo;
    }

    public String getInsureNo() {
        return insureNo;
    }

    public void setInsureNo(String insureNo) {
        this.insureNo = insureNo;
    }

    public double getCoverage() {
        return coverage;
    }

    public void setCoverage(double coverage) {
        this.coverage = coverage;
    }

    public double getPermium() {
        return permium;
    }

    public void setPermium(double permium) {
        this.permium = permium;
    }

    public String getPayMode() {
        return payMode;
    }

    public void setPayMode(String payMode) {
        this.payMode = payMode;
    }

    public String getEffectDate() {
        return effectDate;
    }

    public void setEffectDate(String effectDate) {
        this.effectDate = effectDate;
    }

    public String getAcceptDate() {
        return acceptDate;
    }

    public void setAcceptDate(String acceptDate) {
        this.acceptDate = acceptDate;
    }

    public String getReceiptDate() {
        return receiptDate;
    }

    public void setReceiptDate(String receiptDate) {
        this.receiptDate = receiptDate;
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(String updateDate) {
        this.updateDate = updateDate;
    }

    public List<Attachment> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<Attachment> attachments) {
        this.attachments = attachments;
    }

    public String getPolicyErpId() {
        return policyErpId;
    }

    public void setPolicyErpId(String policyErpId) {
        this.policyErpId = policyErpId;
    }

    public int getPolicyErpFlag() {
        return policyErpFlag;
    }

    public void setPolicyErpFlag(int policyErpFlag) {
        this.policyErpFlag = policyErpFlag;
    }

    public int getPolicyStatusCode() {
        return policyStatusCode;
    }

    public void setPolicyStatusCode(int policyStatusCode) {
        this.policyStatusCode = policyStatusCode;
    }

    public String getPolicyStatusValue() {
        return policyStatusValue;
    }

    public void setPolicyStatusValue(String policyStatusValue) {
        this.policyStatusValue = policyStatusValue;
    }

    /**
     * 同时设置状态码与状态
     * <p>
     * 对状态设置进行特殊处理
     *
     * @param statusCode
     * @param statusValue
     */
    public void setPolicyStatus(int statusCode, String statusValue) {
        setPolicyStatusCode(statusCode);
        if (!TextUtils.isEmpty(statusValue)) {
            setPolicyStatusValue(statusValue);
        } else {
            setPolicyStatusByCode(statusCode);
        }
    }

    /**
     * 为了保持原来的调用不动，添加返回状态的方法
     *
     * @return
     */
    public String getStatus() {
        return policyStatusValue;
    }

    /**
     * 是否是Erp
     *
     * @return
     */
    public boolean isErp() {
        return this.policyErpFlag == 1;
    }

    /**
     * 缴费方式代码
     *
     * @return
     */
    public int getPayPeriodCode() {
        for (Map.Entry<String, Integer> entry : PAY_PERIOD_MAP.entrySet()) {
            if (entry != null) {
                if (entry.getKey().equals(payMode)) {
                    return entry.getValue();
                }
            }
        }
        return -1;
    }

    /**
     * 设置缴费方式代码
     *
     * @return
     */
    public void setPayPeriodByCode(int code) {
        for (Map.Entry<String, Integer> entry : PAY_PERIOD_MAP.entrySet()) {
            if (entry != null) {
                if (entry.getValue() == code) {
                    this.payMode = entry.getKey();
                }
            }
        }
    }

    /**
     * 根据状态码设置保单状态
     *
     * @param code
     */
    public void setPolicyStatusByCode(int code) {
        for (Map.Entry<String, Integer> entry : POLICY_STATUS_MAP.entrySet()) {
            if (entry != null) {
                if (entry.getValue() == code) {
                    this.policyStatusValue = entry.getKey();
                }
            }
        }
    }
}
